

package com.cn.项目.飞机预约管理系统.UserFrame;

import com.cn.项目.utils.JdbcUtils;

import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.*;


public class Person extends JPanel {
    public Person() {
        initComponents();
    }

    //充值监听
    private void button1ActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Recharge();

    }

    //查询监听
    private void button2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null ;
        String uname = textField1.getText();

        try {
            conn = JdbcUtils.getConnection();
            String sql="select * from training.users where uname=?;";
            st = conn.prepareStatement(sql);
            st.setString(1, uname);
            rs  = st.executeQuery();
            if(rs.next()){
                String id = rs.getString("id");
                String password = rs.getString("password");
                String money = rs.getString("money");
                label5.setText(id);
                label6.setText(password);
                label7.setText(money);
            }
        } catch (SQLException e1) {
            e1.printStackTrace();
        }finally {
            JdbcUtils.release(conn,st ,rs );
        }
    }


    //修改个人信息
    private void button3ActionPerformed(ActionEvent e) {
        // TODO add your code here
          new UpdatePerson();
    }



    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        label5 = new JLabel();
        label6 = new JLabel();
        label7 = new JLabel();
        button1 = new JButton();
        textField1 = new JTextField();
        button2 = new JButton();
        button3 = new JButton();

        //======== this ========
        setLayout(null);

        //---- label1 ----
        label1.setText("您的个人信息");
        label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 12f));
        label1.setForeground(new Color(204, 51, 0));
        add(label1);
        label1.setBounds(100, 10, 180, 37);

        //---- label2 ----
        label2.setText("账号：");
        label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 6f));
        add(label2);
        label2.setBounds(55, 130, 85, 35);

        //---- label3 ----
        label3.setText("密码：");
        label3.setFont(label3.getFont().deriveFont(label3.getFont().getSize() + 6f));
        add(label3);
        label3.setBounds(55, 200, 85, 35);

        //---- label4 ----
        label4.setText("余额：");
        label4.setFont(label4.getFont().deriveFont(label4.getFont().getSize() + 6f));
        add(label4);
        label4.setBounds(55, 270, 85, 35);

        //---- label5 ----
        label5.setText("text");
        label5.setFont(label5.getFont().deriveFont(label5.getFont().getSize() + 6f));
        add(label5);
        label5.setBounds(170, 130, 170, 35);

        //---- label6 ----
        label6.setText("text");
        label6.setFont(label6.getFont().deriveFont(label6.getFont().getSize() + 6f));
        add(label6);
        label6.setBounds(170, 205, 170, 35);

        //---- label7 ----
        label7.setText("text");
        label7.setFont(label7.getFont().deriveFont(label7.getFont().getSize() + 6f));
        label7.setForeground(Color.red);
        add(label7);
        label7.setBounds(170, 270, 170, 35);

        //---- button1 ----
        button1.setText("充值");
        button1.setFont(button1.getFont().deriveFont(button1.getFont().getSize() + 6f));
        button1.setForeground(new Color(0, 153, 153));
        button1.addActionListener(e -> button1ActionPerformed(e));
        add(button1);
        button1.setBounds(65, 330, 80, 40);

        //---- textField1 ----
        textField1.setText("输入您的姓名：");
        textField1.setFont(textField1.getFont().deriveFont(textField1.getFont().getSize() + 5f));
        add(textField1);
        textField1.setBounds(40, 65, 145, textField1.getPreferredSize().height);

        //---- button2 ----
        button2.setText("查询");
        button2.setFont(button2.getFont().deriveFont(button2.getFont().getSize() + 6f));
        button2.setForeground(new Color(51, 255, 0));
        button2.addActionListener(e -> button2ActionPerformed(e));
        add(button2);
        button2.setBounds(215, 65, 90, button2.getPreferredSize().height);

        //---- button3 ----
        button3.setText("修改信息");
        button3.setFont(button3.getFont().deriveFont(button3.getFont().getSize() + 6f));
        button3.setForeground(new Color(0, 153, 153));
        button3.addActionListener(e -> {
			button1ActionPerformed(e);
			button3ActionPerformed(e);
			button3ActionPerformed(e);
		});
        add(button3);
        button3.setBounds(190, 330, 115, 40);

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JLabel label5;
    private JLabel label6;
    private JLabel label7;
    private JButton button1;
    private JTextField textField1;
    private JButton button2;
    private JButton button3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
